<%@page import="org.yate.oa.model.LoginEntity"%>
<%@page import="java.text.SimpleDateFormat, java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set value="${pageContext.request.contextPath}" var="ctx" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<link href="${ctx}/css/skin.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/page.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/jquery-ui.css" rel="stylesheet" type="text/css" />
<style type="text/css">
table {
	table-layout: fixed;
}

#staffs td {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
</style>
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/backOffice.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.myPagination.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-ui.min.js"></script>
<script type="text/javascript">
	function dataFormat(date) {
		var year = date.getFullYear();
		var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1)
				: (date.getMonth() + 1);
		var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
		var hour = date.getHours() < 10 ? '0' + date.getHours() : date
				.getHours();
		var minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date
				.getMinutes();
		var second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date
				.getSeconds();
		return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":"
				+ second;
	}
	var obj = {
		on : true,
		type : 'all',
		dataType : '',
		dataStatus : '',
		searchVal : '',
		searchVal2 : '',
		branch : ''
	};
	var belongOrgid =
<%=request.getSession().getAttribute("orgid")%>
	;
	var iszl =
<%=request.getSession().getAttribute("iszl")%>
	;
	$(document)
			.ready(
					function() {
						$("#searchVal1,#searchVal2").datepicker({
							changeMonth : true,
							changeYear : true,
							dateFormat : 'yy-mm-dd',
							maxDate : new Date()
						});
						$
								.ajax({
									type : 'post',
									dataType : 'json',
									url : '${ctx}/performance/post',
									data : {
										type : 'branch'
									},
									success : function(data) {
										if (data.status == 200) {
											var str = '';
											data = data.data;
											if (!iszl) {
												str += '<option selected="selected" value="">请选择</option>';
											}
											for ( var i = 0; i < data.length; i++) {
												if (iszl
														&& data[i].id == belongOrgid) {
													str += '<option value="'+data[i].id+'">'
															+ data[i].orgName
															+ '</option>';
												} else if (!iszl) {
													str += '<option value="'+data[i].id+'">'
															+ data[i].orgName
															+ '</option>';
												}

											}
											$('#branch').html(str);
											if (iszl) {
												search();
											} else {
												page(1);
											}
										}
									}
								});

					});
	function page(pageIndex) {

		$("#demo1").myPagination({
			currPage : pageIndex,
			ajax : {
				on : true,
				dataType : 'json',
				url : '${ctx}/history/post',
				callback : 'showData',
				param : obj
			}
		});
	}

	function showData(data) {
		var rows = data.data.rows;
		var str = '';
		var tmpLeave;
		for ( var i = 0; i < rows.length; i++) {
			if (rows[i].taskType == 'leave') {
				if (rows[i].leaveType == "personal") {
					tmpLeave = "事假";
				} else if (rows[i].leaveType == "sick") {
					tmpLeave = "病假";
				} else if (rows[i].leaveType == "marriage") {
					tmpLeave = "婚假";
				} else if (rows[i].leaveType == "funeral") {
					tmpLeave = "丧假";
				} else if (rows[i].leaveType == "maternity") {
					tmpLeave = "产假";
				} else if (rows[i].leaveType == "father") {
					tmpLeave = "父亲假";
				} else if (rows[i].leaveType == "visiting") {
					tmpLeave = "外派探亲假";
				} else if (rows[i].leaveType == "annual") {
					tmpLeave = "年假";
				}
			}
			str += '<tr>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ ((currPage - 1) * 10 + (i + 1)) + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ (rows[i].status == "completed" ? "已审批"
							: rows[i].status == "refused" ? "未通过" : "处理中")
					+ '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ (rows[i].taskType == "leave" ? "请假(" + tmpLeave + ")"
							: rows[i].taskType == "paidleave" ? "调休" : "加班")
					+ '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ rows[i].creater.trueName + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ dataFormat(new Date(rows[i].makeDate)) + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ dataFormat(new Date(rows[i].beginDate)) + '</td>';
			if (rows[i].taskType != 'workovertime') {
				if(rows[i].days)
				str += '<td height="30" class="left_txt2" align="middle">'
						+ dataFormat(new Date(rows[i].beginDate
								+ (rows[i].days * 24*3600*1000))) + '</td>';
			} else {
				str += '<td height="30" class="left_txt2" align="middle">'
						+ dataFormat(new Date(rows[i].endDate)) + '</td>';
			}

			if (rows[i].taskType == "workovertime") {
				if (rows[i].isKF == 1) {
					str += '<td height="30" class="left_txt2" align="middle">'
							+ ((rows[i].endDate - rows[i].beginDate) / (1000 * 3600 * 6))
									.toFixed(2) + '</td>';
				} else {
					str += '<td height="30" class="left_txt2" align="middle">'
							+ ((rows[i].endDate - rows[i].beginDate) / (1000 * 3600 * 7.5))
									.toFixed(2) + '</td>';
				}
			} else {
				str += '<td height="30" class="left_txt2" align="middle">'
						+ (rows[i].days) + '</td>';
			}
			str += '<td height="30" class="left_txt2" title="'+rows[i].remark+'">'
					+ rows[i].remark + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ rows[i].approver.trueName + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ dataFormat(new Date(rows[i].creationDate)) + '</td>';
			str += '<td height="30" class="left_txt2" align="middle" title="'+rows[i].conclusion+'">'
					+ rows[i].conclusion + '</td>';
			str += '</tr>';
		}
		$('#staffs').html('').html(str);
	}

	function search() {
		var searchVal = $.trim($("#searchVal1").val());
		var searchVal2 = $.trim($("#searchVal2").val());
		if (searchVal == '' && searchVal2 != '') {
			$.msgbox.show({
				message : '开始时间不能为空',
				icon : 'no'
			});
			return;
		}
		if (searchVal != '' && searchVal2 == '') {
			$.msgbox.show({
				message : '结束时间不能为空',
				icon : 'no'
			});
			return;
		}
		var dataType = $('#dataType').select().val();
		var dataStatus = $('#dataStatus').select().val();
		var branch = $('#branch').select().val();
		obj.branch = branch;
		obj.dataType = dataType;
		obj.dataStatus = dataStatus;
		obj.searchVal = searchVal;
		obj.searchVal2 = searchVal2;
		page(1);
	}

	function exportExcel() {
		var searchVal = $.trim($("#searchVal1").val());
		var searchVal2 = $.trim($("#searchVal2").val());
		if (searchVal == '' && searchVal2 != '') {
			searchVal = "";
			searchVal2 = "";
		}
		var dataType = $('#dataType').select().val();
		var dataStatus = $('#dataStatus').select().val();
		var branch = $('#branch').select().val();
		$("#ifmExcel").attr(
				"src",
				"${ctx}/history/post?type=excel&dataType=" + dataType
						+ "&dataStatus=" + dataStatus + "&searchVal="
						+ searchVal + "&searchVal2=" + searchVal2 + "&branch="
						+ branch);
	}
</script>
</head>
<body style="font-size: 62.5%;">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" height="29" valign="top"
				background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/left-top-right.gif" width="17" height="29" /></td>
			<td width="" height="29" valign="top"
				background="${ctx}/images/content-bg.gif"><table width="100%"
					height="31" border="0" cellpadding="0" cellspacing="0"
					class="left_topbg" id="table2">
					<tr>
						<td height="31"><div class="titlebt">审批数据</div></td>
					</tr>
				</table></td>
			<td width="16" valign="top"
				background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/nav-right-bg.gif" width="16" height="29" /></td>
		</tr>
		<tr>
			<td height="71" valign="middle"
				background="${ctx}/images/mail_leftbg.gif">&nbsp;</td>
			<td valign="top" bgcolor="#F7F8F9"><table width="100%"
					height="138" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="13" valign="top">&nbsp;</td>
					</tr>
					<tr>
						<td valign="top"><table width="98%" border="0" align="center"
								cellpadding="0" cellspacing="0">
								<tr>
									<td class="left_txt">当前位置：审批数据</td>
								</tr>
								<tr>
									<td height="20"><table width="100%" height="1" border="0"
											cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
											<tr>
												<td></td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td>
										<button onclick="exportExcel()">导出成Excel</button>
										<table width="100%" height="31" border="0" cellpadding="0"
											cellspacing="0" class="nowtable">
											<tr>
												<td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;审批数据</td>
												<td width="5%" align="right"><img
													onclick="if($('#queryDiv').is(':visible')){$('#queryDiv').hide()}else{$('#queryDiv').show()}"
													src="${ctx }/images/query.png" style="cursor: pointer;"></img>&nbsp;</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td width="100%;" valign="top"
										style="min-height: 350px; height: 350px;">
										<table class="tblExcel" cellpadding="0" cellspacing="0">
											<thead>
												<tr>
													<td height="30" width="4%" class="left_txt2" align="center">序号</td>
													<td height="30" width="4%" class="left_txt2" align="center">状态</td>
													<td height="30" width="5%" class="left_txt2" align="center">类型</td>
													<td height="30" width="6%" class="left_txt2" align="center">申请人</td>
													<td height="30" width="11%" class="left_txt2"
														align="center">填报日期</td>
													<td height="30" width="13%" class="left_txt2"
														align="center">开始时间</td>
													<td height="30" width="13%" class="left_txt2"
														align="center">结束时间</td>
													<td height="30" width="5%" class="left_txt2" align="center">合计（天）</td>
													<td height="30" width="11%" class="left_txt2">备注</td>
													<td height="30" width="7%" class="left_txt2" align="center">审批人</td>
													<td height="30" width="13%" class="left_txt2"
														align="center">审批时间</td>
													<td height="30" width="10%" class="left_txt2"
														align="center">审批结果</td>
												</tr>
											</thead>
											<tbody id="staffs"></tbody>
										</table>
										<div id="demo1"></div>
									</td>
								</tr>
							</table></td>
					</tr>
				</table></td>
			<td background="${ctx}/images/mail_rightbg.gif">&nbsp;</td>
		</tr>
		<tr>
			<td valign="middle" background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/buttom_left2.gif" width="17" height="17" /></td>
			<td height="17" valign="top"
				background="${ctx}/images/buttom_bgs.gif"><img
				src="${ctx}/images/buttom_bgs.gif" width="17" height="17" /></td>
			<td background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/buttom_right2.gif" width="16" height="17" /></td>
		</tr>
	</table>
	<div id="queryDiv"
		style="background-color: #E1E5EE; width: 293px; height: 170px; position: absolute; top: 141px; right: 27px; display: none;">
		<form>
			<table cellpadding="0" cellspacing="0" style="font-size: 13px;">
				<tr>
					<td height="35" width="28%" align="right"><label>类型：</label></td>
					<td><select id="dataType">
							<option selected="selected" value="">--请选择--</option>
							<option value="workovertime">加班</option>
							<option value="paidleave">调休</option>
							<option value="leave">请假</option>
					</select></td>
				</tr>
				<tr>
					<td height="35" align="right"><label>状态：</label></td>
					<td><select id="dataStatus">
							<option selected="selected" value="">--请选择--</option>
							<option value="completed">已审批</option>
							<option value="processing">处理中</option>
							<option value="refused">未通过</option>
					</select></td>
				</tr>
				<tr>
					<td height="35" align="right"><label>部门：</label></td>
					<td><select id="branch">
							<option selected="selected" value="">请选择</option>
					</select></td>
				</tr>
				<tr>
					<td valign="top" align="right" height="35"><label>填表时间：</label></td>
					<td><input type="text" id="searchVal1" readonly="readonly"
						style="width: 75px;"></input> - <input type="text" id="searchVal2"
						readonly="readonly" style="width: 75px;"></input></td>
				</tr>
				<tr>
					<td valign="top" align="center" colspan="2" height="35"><input
						type="button" value="确定" onclick="search()" /> <input
						type="reset" value="重置" /></td>
				</tr>
			</table>
		</form>
	</div>
	<iframe id="ifmExcel" style="width: 0px; height: 0px;"></iframe>
</body>
</html>